package strings

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	s:= "yes我爱哈哈哈!"
	fmt.Println(s)


	fmt.Println(len(s))

	fmt.Println([]byte(s))

	fmt.Println()

	for i,ch :=range s {//ch is rune     (把utf9转成  unicode)
		fmt.Printf("(%d %x)",i,ch)
	}

	fmt.Println()
	fmt.Println()


	fmt.Println("Rune Count ",utf8.RuneCountInString(s))//获取字符数量

	fmt.Println()
	fmt.Println()

	bytes := []byte(s)
	for len(bytes)>0 {
		ch,size := utf8.DecodeRune(bytes)
		bytes = bytes[size:]
		fmt.Printf("%c",ch)
	}
	fmt.Println()
	fmt.Println()

	for i,ch := range []rune(s)  {//重新开了一个rune数组

		fmt.Printf("(%d,%c)",i,ch)

	}
}
